home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / cmprss.exe / CP.CPP < prev    next >
C/C++ Source or Header  |  1993-01-26  |  1KB  |  79 lines

  1. #include <iostream.h>
  2. #include "compress.cls"
  3. #include "decpress.cls"
  4.  
  5. main(int argc, char *argv[])
  6.     {
  7.     if (argc!=4)
  8.         {
  9.         cout<< "Usage: cp <c | d> <file in> <file out>\n";
  10.         return 1;
  11.         }
  12.     switch (argv[1][0])
  13.         {
  14.         case 'c':
  15.         case 'C':
  16.             {
  17.             ifstream fi(argv[2],ios::in | ios::binary);
  18.             if (fi.bad())
  19.                 {
  20.                 cout<<"Can't open input file\n";
  21.                 return 1;
  22.                 }
  23.             fi.flags(0);            // clear \n translation
  24.             cpofstream fo(argv[3]);
  25.             if (fo.bad())
  26.                 {
  27.                 cout<<"Can't open output file\n";
  28.                 return 1;
  29.                 }
  30.  
  31.             char c;
  32.             for (;;)
  33.                 {
  34.                 fi>>c;
  35.                 if (fi.eof())
  36.                     break;
  37.                 fo<<c;
  38.                 }
  39.             fi.close();
  40.             fo.close();
  41.             break;
  42.             }
  43.         case 'd':
  44.         case 'D':
  45.             {
  46.             cpifstream fi(argv[2]);
  47.             if (fi.bad())
  48.                 {
  49.                 cout<<"Can't open input file\n";
  50.                 return 1;
  51.                 }
  52.             ofstream fo(argv[3],ios::out | ios::binary);
  53.             if (fo.bad())
  54.                 {
  55.                 cout<<"Can't open output file\n";
  56.                 return 1;
  57.                 }
  58.  
  59.             char c;
  60.             for (;;)
  61.                 {
  62.                 fi>>c;
  63.                 if (fi.done())        // can't use EOF on binary files ???
  64.                     break;
  65.                 fo<<c;
  66.                 }
  67.             fi.close();
  68.             fo.close();
  69.             break;
  70.             }
  71.         default:
  72.             cout<< "Usage: cp <c | d> <file in> <file out>\n";
  73.             return 1;
  74.         }
  75.  
  76.     return 0;
  77.     }
  78.  
  79.